/*
 * This file is part of ddesktop: remote desktop system for iPad 
 *
 * Copyright (C) 2010 Kazuhiro Satoh
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. if not, see <http://www.gnu.org/licenses/>.
 */


#pragma once
#pragma unmanaged

#include <stdio.h>
#include "AbstractEncoder.h"

#define XMD_H
#undef FAR
extern "C"{
#include "libjpeg/jpeglib.h"
}

namespace DDesktopServer
{
	class LibJpegEncoder : public AbstractEncoder
	{
	private:
		struct jpeg_compress_struct m_cinfo;
		struct jpeg_error_mgr m_jerr;
		char *m_data_buf;
		char *m_header_buf;
		unsigned int m_data_buf_capacity;
		unsigned int m_data_length;
		unsigned int m_header_length;
		unsigned int m_image_width;
		unsigned int m_image_height;
		unsigned int m_image_quality;
		unsigned int m_image_resolution;

	public:

		LibJpegEncoder();
		virtual ~LibJpegEncoder();

		virtual bool Init(int max_width, int max_height);
		virtual const unsigned char* GetHeader(void) const;
		virtual const unsigned char* GetData(void) const;
		virtual int GetHeaderSize(void) const;
		virtual int GetDataSize(void) const;
		virtual bool Encode(char* data, int width, int height, int canvas_width, int canvas_height, int image_quality, int image_resolution);
		virtual bool Encode(char* data, int width, int height, int canvas_width, int canvas_height, int image_quality);

		virtual bool WriteToFile(const char* file_name) const;
	};
}

#pragma managed
